<script setup lang="ts">
import { useHistoryStore } from '@/stores/history'
import { computed } from 'vue'

const historyStore = useHistoryStore()

const formattedHistory = computed(() => {
  return historyStore.history.map(item => ({
    ...item,
    time: new Date(item.timestamp).toLocaleTimeString()
  }))
})
</script>

<template>
  <div class="nes-container with-title history-panel">
    <h3 class="title">操作历史</h3>
    <div class="history-list">
      <div 
        v-for="(item, index) in formattedHistory" 
        :key="index"
        class="history-item"
      >
        <i 
          class="nes-icon is-small"
          :class="{
            'coin': item.type === 'update',
            'trophy': item.type === 'submit'
          }"
        ></i>
        <span class="value">{{ item.value }}</span>
        <span class="time">{{ item.time }}</span>
      </div>
      <div v-if="formattedHistory.length === 0" class="empty-history">
        暂无操作记录
      </div>
    </div>
  </div>
</template>

<style scoped>
.history-panel {
  margin-top: 2rem;
}

.history-list {
  max-height: 200px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem;
  font-size: 0.8rem;
  border-bottom: 2px solid var(--border-color);
}

.history-item:last-child {
  border-bottom: none;
}

.value {
  flex: 1;
}

.time {
  color: #666;
  font-size: 0.7rem;
}

.empty-history {
  text-align: center;
  padding: 1rem;
  color: #666;
  font-size: 0.8rem;
}

/* 自定义滚动条 */
.history-list::-webkit-scrollbar {
  width: 8px;
}

.history-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border: 2px solid var(--border-color);
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border: 2px solid var(--border-color);
}

.history-list::-webkit-scrollbar-thumb:hover {
  background: var(--dark-color);
}
</style> 